package com.badminton.commendSys.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.badminton.common.annotation.Log;
import com.badminton.common.core.controller.BaseController;
import com.badminton.common.core.domain.AjaxResult;
import com.badminton.common.enums.BusinessType;
import com.badminton.commendSys.domain.Equipmentrecommendation;
import com.badminton.commendSys.service.IEquipmentrecommendationService;
import com.badminton.common.utils.poi.ExcelUtil;
import com.badminton.common.core.page.TableDataInfo;

/**
 * 装备推荐Controller
 *
 * @date 2024-07-04
 */
@RestController
@RequestMapping("/commendSys/equipmentrecommendation")
@Api("装备推荐")
public class EquipmentrecommendationController extends BaseController
{
    @Autowired
    private IEquipmentrecommendationService equipmentrecommendationService;

    /**
     * 查询装备推荐列表
     */
    @PreAuthorize("@ss.hasPermi('commendSys:equipmentrecommendation:list')")
    @GetMapping("/list")
    @ApiOperation("查询装备推荐")
    public TableDataInfo list(Equipmentrecommendation equipmentrecommendation)
    {
        System.out.println("查询参数: " + equipmentrecommendation);
        startPage();
        List<Equipmentrecommendation> list = equipmentrecommendationService.selectEquipmentrecommendationList(equipmentrecommendation);
        System.out.println("推荐列表: " + list);
        return getDataTable(list);
    }

    /**
     * 导出装备推荐列表
     */
    @PreAuthorize("@ss.hasPermi('commendSys:equipmentrecommendation:export')")
    @Log(title = "装备推荐", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出装备推荐")
    public void export(HttpServletResponse response, Equipmentrecommendation equipmentrecommendation)
    {
        System.out.println("导出参数: " + equipmentrecommendation);
        List<Equipmentrecommendation> list = equipmentrecommendationService.selectEquipmentrecommendationList(equipmentrecommendation);
        System.out.println("导出列表: " + list);
        ExcelUtil<Equipmentrecommendation> util = new ExcelUtil<Equipmentrecommendation>(Equipmentrecommendation.class);
        util.exportExcel(response, list, "装备推荐数据");
    }

    /**
     * 获取装备推荐详细信息
     */
    @PreAuthorize("@ss.hasPermi('commendSys:equipmentrecommendation:query')")
    @GetMapping(value = "/{recommendationid}")
    @ApiOperation("获取装备推荐")
    public AjaxResult getInfo(@PathVariable("recommendationid") Long recommendationid)
    {
        Equipmentrecommendation result = equipmentrecommendationService.selectEquipmentrecommendationByRecommendationid(recommendationid);
        return success(result);
    }


    /**
     * 新增装备推荐
     */
    @PreAuthorize("@ss.hasPermi('commendSys:equipmentrecommendation:add')")
    @Log(title = "装备推荐", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增装备推荐")
    public AjaxResult add(@RequestBody Equipmentrecommendation equipmentrecommendation)
    {
        System.out.println("新增参数: " + equipmentrecommendation);
        int result = equipmentrecommendationService.insertEquipmentrecommendation(equipmentrecommendation);
        System.out.println("新增结果: " + result);
        return toAjax(result);
    }

    /**
     * 修改装备推荐
     */
    @PreAuthorize("@ss.hasPermi('commendSys:equipmentrecommendation:edit')")
    @Log(title = "装备推荐", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改装备推荐")
    public AjaxResult edit(@RequestBody Equipmentrecommendation equipmentrecommendation)
    {
        System.out.println("修改参数: " + equipmentrecommendation);
        int result = equipmentrecommendationService.updateEquipmentrecommendation(equipmentrecommendation);
        System.out.println("修改结果: " + result);
        return toAjax(result);
    }

    /**
     * 删除装备推荐
     */
    @PreAuthorize("@ss.hasPermi('commendSys:equipmentrecommendation:remove')")
    @Log(title = "装备推荐", businessType = BusinessType.DELETE)
    @DeleteMapping("/{recommendationids}")
    @ApiOperation("删除装备推荐")
    public AjaxResult remove(@PathVariable Long[] recommendationids)
    {
        System.out.println("删除ID列表: " + Arrays.toString(recommendationids));
        int result = equipmentrecommendationService.deleteEquipmentrecommendationByRecommendationids(recommendationids);
        System.out.println("删除结果: " + result);
        return toAjax(result);
    }
}
